<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission" />
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
<!--        <el-form size="small" label-width="70px">-->
<!--          <el-row :gutter="10">-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户名称">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售部门">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售人员">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户分类">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户区域">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <rrOperation :crud="crud"/>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
      </div>
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索"   close-on-click-modal :visible.sync="crud.props.searchToggle"
                 width="70%">
        <el-form size="small" label-width="70px" >
          <el-row :gutter="10">
            <el-col v-if="isBusDate" span="12">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
<!--            <el-col v-if="isBusDate" span="12">-->
<!--              <el-form-item label="业务日期">-->
<!--                <el-date-picker-->
<!--                  v-model="dataExtent"-->
<!--                  type="daterange"-->
<!--                  @change="getValue()"-->
<!--                  align="right"-->
<!--                  unlink-panels-->
<!--                  style="width: 100%"-->
<!--                  format="yyyy - MM - dd "-->
<!--                  value-format="yyyy-MM-dd"-->
<!--                  default-value-->
<!--                  range-separator=""-->
<!--                  start-placeholder="开始日期"-->
<!--                  end-placeholder="结束日期"-->
<!--                  :picker-options="pickerOptions">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col v-if="!isBusDate" span="12">
              <el-form-item label="开单日期">
                <el-date-picker
                  v-model="dataExtent1"
                  type="daterange"
                  @change="getDateChange()"
                  align="right"
                  unlink-panels
                  style="width: 100%"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  range-separator=""
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="日期类型">
                <el-select v-model="dateType" collapse-tags  class="edit-input" placeholder="请选择日期类型" style="width: 100%;">
                  <el-option label="业务日期" value="1"/>
                  <el-option label="开单日期" value="2"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col span="12" >
              <el-form-item label="验收日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.acceptStartDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.acceptEndDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col span="12" >
              <el-form-item label="核销日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.cancelStartDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.cancelEndDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col span="12" >
              <el-form-item label="发货日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.sendStartDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.sendEndDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="装车日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.loadStartDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.loadEndDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="商品类型">
              <zSelect multiple :value.sync="query.goodsTagIds" url="api/dropDown/basGoodsTagList" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
                <el-form-item label="客户分类">
                  <treeselect
                    v-model="customerTypeIds"
                    :options="customerTypeList"
                    placeholder="请选择客户分类"
                    style="width: 100%"
                    :normalizer="normalizer"
                    multiple
                    @select="onCustomerNode"
                  />
                </el-form-item>
              </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商">
<!--                <zSelect multiple :value.sync="customerIds"  url="/api/dropDown/basCustomerList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'供应商编码',width:'100'},{prop:'name',label:'供应商名称',width: '280'}]"
                  :value.sync="query.customerIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商贸公司">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.fCustomerIds"
                  placeholder="请选择商贸公司"
                  url="/api/dropDown/basCustomerList"
                  :params="{type:2}"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="制单人">
                <!--                <zSelect multiple :value.sync="query.createUserIds"   url="api/dropDown/sysUserList"    style="width: 100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.createUserIds"
                  placeholder="请选择制单人"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务员">
                <!--                <zSelect multiple :value.sync="query.createUserIds"   url="api/dropDown/sysUserList"    style="width: 100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.userIds"
                  placeholder="请选择业务员"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据类型">
                <el-select v-model="orderType" collapse-tags multiple class="edit-input" placeholder="请选择单据状态" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.t_report_sale_statistics_order_type"
                    :key="index"
                    multiple
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户名称">
<!--                <el-input v-model="query.goodsKeyword" placeholder="输入商品进行搜索"/>-->
<!--                <zSelect multiple :value.sync="customerIds"  url="/api/dropDown/basCustomerList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'客户编码',width:'100'},{prop:'name',label:'客户名称',width: '280'}]"
                  :value.sync="query.customerIds"
                  placeholder="请选择客户"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品名称">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="商品品牌">
              <table-select
                :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                :value.sync="query.goodsBrandIds"
                placeholder="请选择品牌"
                url="/api/dropDown/basGoodsBrandList"
              ></table-select>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="商品分类">
              <treeselect
                v-model="goodsTypeIds"
                :options="areaList"
                placeholder="商品"
                style="width: 100%"
                :normalizer="normalizer"
                multiple
                @input="getgoodsType"
              />
            </el-form-item>
          </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="仓库">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.warehouseIds"
                  placeholder="请选择仓库"
                  url="/api/dropDown/basWarehouseList"
                ></table-select>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="所属商贸">-->
<!--                <zSelect multiple :value.sync="fCustomerIds"  url="/api/dropDown/basCustomerList"  :params="{type:2}"-->
<!--                         style="width:  100%;"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="所属二批">
              <table-select
                :tableColumns="[{prop:'code',label:'二批编码',width:'100'},{prop:'name',label:'二批名称',width: '280'}]"
                :value.sync="query.sCustomerIds"
                placeholder="请选择所属二批"
                url="/api/dropDown/basCustomerList"
                :params="{type:3}"
              ></table-select>
            </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="所属总店">
              <table-select
                :tableColumns="[{prop:'code',label:'总店编码',width:'100'},{prop:'name',label:'总店名称',width: '280'}]"
                :value.sync="query.pCustomerIds"
                placeholder="请选择所属总店"
                url="/api/dropDown/basCustomerList"
                :params="{customerAttr:1}"
              ></table-select>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否发货为准" label-width="100px">
                <el-select v-model="query.isBasedOnSend" collapse-tags  class="edit-input"  style="width: 100%;">
                  <el-option label="是" value="1"/>
                  <el-option label="否" value="0"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="销售类型">
                <el-select v-model="saleType" collapse-tags multiple class="edit-input" placeholder="请选择单据状态" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.sale_type"
                    :key="index"
                    multiple
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
              <el-form-item label="小计列">
                <el-checkbox-group
                  v-model="groupColumn" @change="getChange"  class="flex flex-row flex-wrap">
                  <el-checkbox v-for="item in groupColumnList"
                               :disabled="item.value ==['goodsId','userId']"
                               :label="item.value"
                               :key="item.value"
                               :value="item.value" >{{item.label}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="flex fow-reverse" >
            <el-button class="filter-item"  size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery" >重置</el-button>
          </el-row>
        </el-form>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<!--          <el-form-item label="业务日期">-->
<!--            <el-input v-model="form.busDate" style="width: 370px;" />-->
<!--          </el-form-item>-->
          <el-form-item label="单据类型(1:销售订单 2:销售退货 3:回瓶回箱)">
            <el-input v-model="form.orderType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户id">
            <el-input v-model="form.customerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户编码">
            <el-input v-model="form.customerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户名称">
            <el-input v-model="form.customerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商贸公司ids">
            <el-input v-model="form.fCustomerIds" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商贸公司编码">
            <el-input v-model="form.fCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商贸公司名称">
            <el-input v-model="form.fCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属二批ids">
            <el-input v-model="form.sCustomerIds" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属二批编码">
            <el-input v-model="form.sCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属二批名称">
            <el-input v-model="form.sCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店id">
            <el-input v-model="form.pCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店编码">
            <el-input v-model="form.pCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店名称">
            <el-input v-model="form.pCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场id">
            <el-input v-model="form.mCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场编码">
            <el-input v-model="form.mCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场名称">
            <el-input v-model="form.mCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门id">
            <el-input v-model="form.deptId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门编码">
            <el-input v-model="form.deptCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门名称">
            <el-input v-model="form.deptName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员编码">
            <el-input v-model="form.userCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员名称">
            <el-input v-model="form.userName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库id">
            <el-input v-model="form.warehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库编码">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="form.goodsId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品编码">
            <el-input v-model="form.goodsCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.goodsName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装类型(1:纸箱 2:塑箱 3:其他)">
            <el-input v-model="form.packageType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="条形码">
            <el-input v-model="form.barcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱装条形码">
            <el-input v-model="form.boxBarcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="助记符">
            <el-input v-model="form.helpSign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌id">
            <el-input v-model="form.goodsBrandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌编码">
            <el-input v-model="form.goodsBrandCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌名称">
            <el-input v-model="form.goodsBrandName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类id">
            <el-input v-model="form.goodsTypeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类编码">
            <el-input v-model="form.goodsTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类名称">
            <el-input v-model="form.goodsTypeName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型id">
            <el-input v-model="form.goodsTagId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型编码">
            <el-input v-model="form.goodsTagCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型名称">
            <el-input v-model="form.goodsTagName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位id">
            <el-input v-model="form.boxUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位编码">
            <el-input v-model="form.boxUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位名称">
            <el-input v-model="form.boxUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数单位计量数">
            <el-input v-model="form.boxUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位数量">
            <el-input v-model="form.boxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位id">
            <el-input v-model="form.mainUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位编码">
            <el-input v-model="form.mainUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位名称">
            <el-input v-model="form.mainUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位计量数">
            <el-input v-model="form.mainUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位数量">
            <el-input v-model="form.mainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="form.goodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数">
            <el-input v-model="form.boxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税金额">
            <el-input v-model="form.taxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税金额">
            <el-input v-model="form.noTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="税额">
            <el-input v-model="form.tax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货数量">
            <el-input v-model="form.sendGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货箱数">
            <el-input v-model="form.sendBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货箱单位数量">
            <el-input v-model="form.sendBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货主单位数量">
            <el-input v-model="form.sendMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货含税金额">
            <el-input v-model="form.sendTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货未税金额">
            <el-input v-model="form.sendNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发货税额">
            <el-input v-model="form.sendTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货数量">
            <el-input v-model="form.returnGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货箱数">
            <el-input v-model="form.returnBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货箱单位数量">
            <el-input v-model="form.returnBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货主单位数量">
            <el-input v-model="form.returnMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货含税金额">
            <el-input v-model="form.returnTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货未税金额">
            <el-input v-model="form.returnNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退货税额">
            <el-input v-model="form.returnTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱数量">
            <el-input v-model="form.returnBottleBoxGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱箱数">
            <el-input v-model="form.returnBottleBoxBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱箱单位数量">
            <el-input v-model="form.returnBottleBoxBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱主单位数量">
            <el-input v-model="form.returnBottleBoxMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱含税金额">
            <el-input v-model="form.returnBottleBoxTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱未税金额">
            <el-input v-model="form.returnBottleBoxNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回瓶回箱税额">
            <el-input v-model="form.returnBottleBoxTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收数量">
            <el-input v-model="form.acceptGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱数">
            <el-input v-model="form.acceptBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱单位数量">
            <el-input v-model="form.acceptBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收主单位数量">
            <el-input v-model="form.acceptMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收含税金额">
            <el-input v-model="form.acceptTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收未税金额">
            <el-input v-model="form.acceptNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收税额">
            <el-input v-model="form.acceptTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="已核销金额">
            <el-input v-model="form.cancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未核销金额">
            <el-input v-model="form.unCancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品备注">
            <el-input v-model="form.goodsRemark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
<!-- 
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu> -->
      <!-- 表格配置 -->
      <!-- <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog> -->

      <!--表格渲染-->
      <el-table ref="table" stripe border v-loading="crud.loading" :data="crud.data" size="small"
                style="width: 100%;" v-if="isShowTable"
                @header-dragend="changeColWidth"
                show-summary
                height="700"
                :summary-method="sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
<!--        <el-table-column-->
<!--          v-if="item.visible"-->
<!--          v-for="(item, index) in crud.header"-->
<!--          :key="`col_${index}`"-->
<!--          :prop="item.prop"-->
<!--          :label="columnLabel(item)"-->
<!--          :width="item.width + 'px'"-->
<!--          :data-porp='item.prop'-->
<!--          @contextmenu.native="showMenu"-->
<!--          @header-dragend="changeColWidth"-->
<!--        >-->
          <!-- 自定义渲染模版 -->
<!--          <template slot-scope="scope">-->
<!--            &lt;!&ndash; 当列key为 sort 时，渲染一个手柄icon &ndash;&gt;-->
<!--            <template v-if="item.prop =='sort'">-->
<!--              <div class="handle_move">-->
<!--                <i :class="scope.row['sort']" />-->
<!--              </div>-->
<!--            </template>-->
<!--            <template v-else>-->
<!--              <span v-if="item.type == 1" style="margin-left: 10px">{{scope.row[`${item.prop}`]}}</span>-->
<!--              <span v-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>-->
<!--              <span v-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>-->
<!--            </template>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.busDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('orderType')" prop="orderType" label="单据类型" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('customerId')" prop="customerCode" label="客户编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('customerId')" prop="customerName" label="客户名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('fCustomerId')" prop="fCustomerCode" label="供应商编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('fCustomerId')" prop="fCustomerName" label="供应商名称" />
<!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('sCustomerId')" prop="sCustomerCode" label="所属二批编码" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('sCustomerId')"  prop="sCustomerName" label="所属二批" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('pCustomerId')" prop="pCustomerName" label="所属总店" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('createUserId')" prop="createUserName" label="制单人" />

        <!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('customerId')"  prop="mCustomerCode" label="所属商场编码" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('customerId')"  prop="mCustomerName" label="所属商场名称" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('deptId')" prop="deptCode" label="部门编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('deptId')" prop="deptName" label="部门名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('userId')" prop="userCode" label="人员编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('userId')" prop="userName" label="人员名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('warehouseId')" prop="warehouseCode" label="仓库编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('warehouseId')"  prop="warehouseName" label="仓库名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="goodsCode"  label="商品编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="goodsName" label="商品名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="packageType" label="包装类型" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('barcode')" prop="barcode" label="条形码" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="boxBarcode" label="箱装条形码" />
<!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="helpSign" label="助记符" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsId')" prop="model" label="规格型号" />
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsBrandId')"  prop="goodsBrandName" label="品牌" />
<!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsTypeId')" prop="goodsTypeCode" label="商品分类编码" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsTypeId')" prop="goodsTypeName" label="商品分类" />
<!--        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsTagId')" prop="goodsTagCode" label="商品类型编码" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnSelectList.includes('goodsTagId')" prop="goodsTagName" label="商品类型" />


<!--        <el-table-column v-if="columns.visible('boxUnitCode')" prop="boxUnitCode" label="箱单位编码" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitName')" prop="boxUnitName" label="箱单位名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱数单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('boxNum')" prop="boxNum" label="箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCode')" prop="mainUnitCode" label="主单位编码" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="主单位名称" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCount')" prop="mainUnitCount" label="主单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('mainNum')" prop="mainNum" label="主单位数量" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCount')" prop="goodsCount" label="订单数量" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.goodsCount }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="订单箱数" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.boxCount }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxAmount')" prop="taxAmount" label="订单金额" >
        <template slot-scope="scope">
          <div style="width: 100%;" class="flex flex-reverse">
          {{ scope.row.taxAmount.toFixed(2) }}
          </div>
        </template>
        </el-table-column>
        <el-table-column prop="saleGoodsCount" label="销售数量" />
        <el-table-column prop="saleBoxCount" label="销售箱数" />
        <el-table-column  prop="saleTaxAmount" label="销售金额" />
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('tax')" prop="tax" label="税额" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sendGoodsCount')" prop="sendGoodsCount" label="发货数量" >
        <template
        slot-scope="scope"
        >
          <div style="width: 100%;" class="flex flex-reverse">
            {{ scope.row.sendGoodsCount }}
          </div>
        </template>
        </el-table-column>

        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sendBoxCount')" prop="sendBoxCount" label="发货箱数" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.sendBoxCount }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('sendBoxNum')" prop="sendBoxNum" label="发货箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('sendMainNum')" prop="sendMainNum" label="发货主单位数量" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sendTaxAmount')" prop="sendTaxAmount" label="发货金额" >
          <template slot-scope="scope">
            <div style="width: 100%;" class="flex flex-reverse">
            {{ scope.row.sendTaxAmount.toFixed(2) }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sendNoTaxAmount')" prop="sendNoTaxAmount" label="发货未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sendTax')" prop="sendTax" label="发货税额" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnGoodsCount')" prop="returnGoodsCount" label="退货数量" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.returnGoodsCount }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBoxCount')" prop="returnBoxCount" label="退货箱数" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.returnBoxCount }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('returnBoxNum')" prop="returnBoxNum" label="退货箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnMainNum')" prop="returnMainNum" label="退货主单位数量" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnTaxAmount')" prop="returnTaxAmount" label="退货金额" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.returnTaxAmount.toFixed(2) }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnNoTaxAmount')" prop="returnNoTaxAmount" label="退货未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnTax')" prop="returnTax" label="退货税额" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBottleBoxGoodsCount')" prop="returnBottleBoxGoodsCount" label="回箱数量" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.returnBottleBoxGoodsCount }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBottleBoxBoxCount')" prop="returnBottleBoxBoxCount" label="回箱箱数" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.returnBottleBoxBoxCount }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('returnBottleBoxBoxNum')" prop="returnBottleBoxBoxNum" label="回瓶回箱箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnBottleBoxMainNum')" prop="returnBottleBoxMainNum" label="回瓶回箱主单位数量" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBottleBoxTaxAmount')" prop="returnBottleBoxTaxAmount" label="回箱金额" >
          <template slot-scope="scope">
            <div style="width: 100%;" class="flex flex-reverse">
            {{ scope.row.returnBottleBoxTaxAmount.toFixed(2) }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBottleBoxNoTaxAmount')" prop="returnBottleBoxNoTaxAmount" label="回瓶回箱未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('returnBottleBoxTax')" prop="returnBottleBoxTax" label="回瓶回箱税额" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptGoodsCount')" prop="acceptGoodsCount" label="验收数量" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.acceptGoodsCount }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptBoxCount')" prop="acceptBoxCount" label="验收箱数" >
          <template
            slot-scope="scope"
          >
            <div style="width: 100%;" class="flex flex-reverse">
              {{ scope.row.acceptBoxCount }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('acceptBoxNum')" prop="acceptBoxNum" label="验收箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('acceptMainNum')" prop="acceptMainNum" label="验收主单位数量" />-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTaxAmount')" prop="acceptTaxAmount" label="验收金额" >
          <template slot-scope="scope">
            <div style="width: 100%;" class="flex flex-reverse">
            {{ scope.row.acceptTaxAmount.toFixed(2) }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptNoTaxAmount')" prop="acceptNoTaxAmount" label="验收未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTax')" prop="acceptTax" label="验收税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelAmount')" prop="cancelAmount" label="已核金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('unCancelAmount')" prop="unCancelAmount" label="未核金额" />-->
<!--        <el-table-column v-if="columns.visible('goodsRemark')" prop="goodsRemark" label="商品备注" />-->
<!--        <el-table-column v-permission="['admin','reportSaleStatistics:edit','reportSaleStatistics:del']" label="操作" width="150px" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
<!--      <pagination/>-->
      <el-pagination
        :current-page.sync="crud.page.page"
        :page-size.sync="crud.page.size"
        :total="crud.page.total"
        :page-sizes="[10, 20, 30, 40, 50, 100, 500]"
        layout="sizes, prev, pager, next"
        style="margin-top: 8px; position: fixed;bottom:35px"
        @size-change="onGet"
        @current-change="onGet"
      />
    </div>
  </div>
</template>

<script>
import crudReportSaleStatistics from '@/api/erp/reportSaleStatistics'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportSaleStatistics'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";


// crud交由presenter持有
const defaultCrud = CRUD({ title: '销售统计报表',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false,
  },
  // groupColumn:['goodsId','userId'],
  query:{
    groupColumn:'goodsId,userId',
    startDate: new Date().toISOString().split('T')[0],
    endDate: new Date().toISOString().split('T')[0]
  },
  url: 'api/reportSaleStatistics', sort: '',
  crudMethod: { ...crudReportSaleStatistics }})
const defaultForm = {
  busDate: null,
  orderType: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  fCustomerIds: null,
  fCustomerCode: null,
  fCustomerName: null,
  sCustomerIds: null,
  pCustomerIds: null,
  sCustomerCode: null,
  sCustomerName: null,
  pCustomerId: null,
  pCustomerCode: null,
  pCustomerName: null,
  mCustomerId: null,
  mCustomerCode: null,
  mCustomerName: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  warehouseId: null,
  warehouseCode: null,
  warehouseName: null,
  goodsId: null,
  goodsCode: null,
  goodsName: null,
  packageType: null,
  barcode: null,
  boxBarcode: null,
  helpSign: null,
  model: null,
  goodsBrandId: null,
  goodsBrandCode: null,
  goodsBrandName: null,
  goodsTypeId: null,
  goodsTypeCode: null,
  goodsTypeName: null,
  goodsTagId: null,
  goodsTagCode: null,
  goodsTagName: null,
  boxUnitId: null,
  boxUnitCode: null,
  boxUnitName: null,
  boxUnitCount: null,
  boxNum: null,
  mainUnitId: null,
  mainUnitCode: null,
  mainUnitName: null,
  mainUnitCount: null,
  mainNum: null,
  goodsCount: null,
  boxCount: null,
  taxAmount: null,
  noTaxAmount: null,
  tax: null,
  sendGoodsCount: null,
  sendBoxCount: null,
  sendBoxNum: null,
  sendMainNum: null,
  sendTaxAmount: null,
  sendNoTaxAmount: null,
  sendTax: null,
  returnGoodsCount: null,
  returnBoxCount: null,
  returnBoxNum: null,
  returnMainNum: null,
  returnTaxAmount: null,
  returnNoTaxAmount: null,
  returnTax: null,
  returnBottleBoxGoodsCount: null,
  returnBottleBoxBoxCount: null,
  returnBottleBoxBoxNum: null,
  returnBottleBoxMainNum: null,
  returnBottleBoxTaxAmount: null,
  returnBottleBoxNoTaxAmount: null,
  returnBottleBoxTax: null,
  acceptGoodsCount: null,
  acceptBoxCount: null,
  acceptBoxNum: null,
  acceptMainNum: null,
  acceptTaxAmount: null,
  acceptNoTaxAmount: null,
  acceptTax: null,
  cancelAmount: null,
  unCancelAmount: null,
  goodsRemark: null,
  id: null
}
export default {
  name: 'ReportSaleStatistics',
  components: { pagination, crudOperation, rrOperation, udOperation,Treeselect,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts:['t_report_sale_statistics_order_type','common_order_status','sale_type'],
  mounted(){
    // if(window.name == ""){
    //   console.log("首次被加载");
    //   // 在首次进入页面时我们给window.name设置一个固定值(isRefresh)
    //   window.name = "isRefresh";
    // }else if(window.name == "isRefresh"){
    //   console.log("页面被刷新");
      getBasGoodsTypeTree({size:999}).then(res=>{
        this.areaList = res.data
      })
      this.groupColumn=['goodsId','userId','sCustomerId']
      this.query.groupColumn='goodsId,userId,sCustomerId'
      this.groupColumnSelectList=['goodsId','userId','sCustomerId']

    // this.crud.refresh()
    // }
    const date  = new Date().toISOString().split('T')[0]
    this.dataExtent[0] = date
    this.dataExtent[1] = date
    this.crud.props.searchToggle = false
  },
  created() {
    // if(window.name == ""){
    //   console.log("首次被加载");
    //   // 在首次进入页面时我们给window.name设置一个固定值(isRefresh)
    //   window.name = "isRefresh";
    // }else if(window.name == "isRefresh"){
    //   console.log("页面被刷新");
    getCustomerTypeTree({size:999}).then(res=>{
      this.customerTypeList = res
    }),
      getBasGoodsTypeTree({size:999}).then(res=>{
        this.areaList = res.data
      })
      this.groupColumn=['goodsId','userId','sCustomerId']
      this.query.groupColumn='goodsId,userId,sCustomerId'
      this.groupColumnSelectList=['goodsId','userId','sCustomerId']
    // }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  data() {
    return {
      fCustomerIds:[],
      total:0,
      areaList:[],
      orderType:[],
      saleType:[],
      goodsTagIds:[],
      customerTypeIds:[],
      orderStatus:[],
      dialogVisible:false,
      dataExtent:[],
      dataExtent1:[],
      datechange:[],
      goodsTypeIds:[],
      goodsBrandIds:[],
      warehouseIds:[],
      sCustomerIds:[],
      pCustomerIds:[],
      customerIds:[],
      customerId:[],
      goodsIds:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      permission: {
        add: ['admin', 'reportSaleStatistics:add'],
        edit: ['admin', 'reportSaleStatistics:edit'],
        del: ['admin', 'reportSaleStatistics:del'],
        import: ['admin', 'reportSaleStatistics:import'],
        export: ['admin', 'reportSaleStatistics:export'],
        copy: ['admin', 'reportSaleStatistics:copy'],
        upload: ['admin', 'reportSaleStatistics:upload'],
        download: ['admin', 'reportSaleStatistics:download'],
      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
      groupColumn: ['goodsId','userId'],
      goodsId:null,
      warehouseId:null,
      storehouseId: null,
      goodsBrandId: null,
      goodsTypeId: null,
      goodsTagId: null,
      deptId: null,
      userId: null,
      barcode: null,
      fCustomerId:null,
      sCustomerId:null,
      pCustomerId:null,
      multiple: true,
      groupColumnSelectList:[],
      groupColumnList: [{
        label: '商品',
        value: 'goodsId'
      },{
        label: '客户',
        value: 'customerId'
      },{
        label: '商品品牌',
        value: 'goodsBrandId'
      },{
        label: '商品分类',
        value: 'goodsTypeId'
      },{
        label: '商品类型',
        value: 'goodsTagId'
      },{
        label: '部门',
        value: 'deptId'
      },{
        label: '业务员',
        value: 'userId'
      },{
        label: '仓库',
        value: 'warehouseId'
      },{
        label: '条形码',
        value: 'barcode'
      },{
        label: '供应商',
        value: 'fCustomerId'
      },{
        label: '所属二批',
        value: 'sCustomerId'
      },{
        label: '所属总店',
        value: 'pCustomerId'
      },{
        label: '制单人',
        value: 'createUserId'
      }],
      isBusDate: true,
      dateType: '1'
    }
  },
  watch: {
    dateType(n){
      if (n == '1'){
        this.isBusDate = true
        this.query.createStartDate=null
        this.query.createEndDate=null
      }else {
        this.isBusDate = false
        this.query.startDate=null
        this.query.endDate=null
      }
    },
    'groupColumnSelectList':{
      handler(n){
        let groupColumn =this.groupColumnSelectList.join(',')
        this.$set(this.query,'groupColumn',groupColumn)
      },
      deep: true
    },
    customerTypeIds(n){
      if (!n.length){
        this.query.customerTypeIds = null
      }
    },
  },
  methods: {
    
    onCustomerNode(node){
      this.query.customerTypeIds = this.getNode(node,this.query.customerTypeIds?this.query.customerTypeIds:'')
    },
    getSelectSum(type){
      let i  = 0
      this.crud.selections.forEach(item=>{
        i+=item[type]
      })
      return i
    },
    sumRow({columns, data}) {
      const sums = []
      for (let i in columns) {
        const prop = this.crud.summary[columns[i].property]
        if (prop){
          sums[i] = <p>{this.getSelectSum(columns[i].property)}<hr />{prop}</p>
        }else {
          sums[i] = ''
        }
      }
      sums[0] =
        <p>
          选中合计
          <hr />
          合计
        </p>
      return sums
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getChange(val){
      this.groupColumnSelectList = val
      console.log(val)
    },
    getValue(e){
      if (this.dataExtent){
        this.query.startDate = this.dataExtent[0]
        this.query.endDate = this.dataExtent[1]
      }else {
        this.query.startDate = null
        this.query.endDate = null
      }
    },
    // getValue(e){
    //   this.query.startDate = this.dataExtent[0]
    //   this.query.endDate = this.dataExtent[1]
    // },
    getDateChange(e){
      this.query.createStartDate = this.dataExtent1[0]
      this.query.createEndDate = this.dataExtent1[1]
    },
    getgoodsType(val){
      let str=''
      val.forEach(item=>{
        const  itemNode=this.getTreeName(this.areaList,item)
        console.log(itemNode)
        str=this.getNode(itemNode,str)
      })
      this.query.goodsTypeIds = str
      console.log(this.query.goodsTypeIds)
    },
    getTreeName(treeList,id){
      let _this=this
      for(let i=0;i<treeList.length;i++){
        let treeItem=treeList[i]
        if(treeItem.id===id){
          return treeItem
        }else{
          if(treeItem.children && treeItem.children.length>0){
            let res=_this.getTreeName(treeItem.children,id)
            if(res){
              return res
            }
          }
        }
      }
    },
    delgoodsType(node){
      const list = this.getNode(node,'').split(',')
      const oldList = this.query.goodsTypeIds.split(',')
      for(let i =oldList.length;i>0;i--){
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])){
          oldList.splice(i,1)
        }
      }
      this.query.goodsTypeIds = oldList.join(',')
      console.log(this.query.goodsTypeIds)
    },
    getNode(node,str){
      if (node.children){
        for (let i =0;i<node.children.length;i++){
          str = this.getNode(node.children[i],str)
        }
      }
      return str+=node.id+ ','
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    init(){
      this.page = 1
    },
    onGet(){
      const that =this
      get({...this.query,...this.crud.page}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        that.crud.summary = res.data.summary
      })
    },
    resetQuery(){
      this.query = {
        customerIds:null,
        customerKeyword:'',
        goodsIds:null,
        endDate:null,
        orderCode:null,
        orderType: null,
        saleType: null,
        goodsTagIds: null,
        goodsKeyword:'',
        goodsTypeIds:null,
        goodsBrandIds:null,
        orderRemark:'',
        goodsRemark: '',
        groupColumn:'',
        orderStatus: null,
        warehouseIds: null,
        sCustomerIds:null,
        pCustomerIds:null,
        startDate:null,
        createStartDate:null,
        createEndDate:null,
        page:1,
        size:10,
      }
      this.fCustomerIds=[],
      this.goodsTypeIds = []
      this.orderType  = []
      this.saleType = []
      this.goodsTagIds = []
      this.goodsBrandIds = []
      this.customerTypeIds = []
      this.orderStatus  = []
      this.warehouseIds = []
      this.sCustomerIds=[]
      this.pCustomerIds=[]
      this.dataExtent = []
      this.dataExtent1 = []
      this.customerIds = []
      this.goodsIds = []
      this.groupColumn=[]
      this.groupColumnSelectList=[]
      this.crud.resetQuery()
      this.onGet()
    },
    queryReport(){
      console.log('33333',this.query.customerTypeIds);
      this.query.saleType = this.saleType.length?this.saleType.join(','):''
      this.query.orderType = this.orderType.length?this.orderType.join(','):''
      // this.query.goodsBrandIds = this.goodsBrandIds.length?this.goodsBrandIds.join(','):''
      this.query.orderStatus = this.orderStatus.length?this.orderStatus.join(','):''
      // this.query.goodsTagIds = this.goodsTagIds.length?this.orderStatus.join(','):''
      // this.query.warehouseIds= this.warehouseIds.length?this.warehouseIds.join(','):''
      // this.query.sCustomerIds=this.sCustomerIds.length?this.sCustomerIds.join(','):''
      // this.query.pCustomerIds=this.pCustomerIds.length?this.pCustomerIds.join(','):''
      // this.query.fCustomerIds = this.fCustomerIds.length?this.fCustomerIds.join(','):''
      // this.query.customerIds= this.customerIds.length?this.customerIds.join(','):''
      // this.query.goodsIds= this.goodsIds.length?this.goodsIds.join(','):''
      this.init()
      this.onGet()
      this.crud.props.searchToggle = false
    },
    getGroupColumn(){
      let str = ''
      for(let i=0;i<this.groupColumnSelectList.length;i++){
        const group = this.groupColumnList.find(val=> val.value == this.groupColumnSelectList[i])
        str+=i<this.groupColumnSelectList.length?`${group.label}:${group.value}|`:`${group.label}:${group.value}`
      }

      return str
    }
  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .flex{
    display: flex;
  }
  .fow-reverse{
    flex-direction: row-reverse;
  }
  .float{
    float: left;
  }
</style>

